/* Author : Putri Andita R
 * 		    091511059
 * Proyek 4*/

package jtk.project4.fleet.screen.pmScheduleSetup;

import java.awt.FlowLayout;
import java.util.List;

import javax.swing.SortOrder;

import jtk.project4.fleet.action.CancelAction;
import jtk.project4.fleet.action.CancelMaintenanceTaskAction;
import jtk.project4.fleet.action.CancelPMScheduleSetupAction;
import jtk.project4.fleet.event.PMScheduleSetupEvent;
import jtk.project4.fleet.field.MainScreenPMScheduleSetupField;
import jtk.project4.fleet.field.PMServicesField;
import jtk.project4.fleet.field.ScheduleField;
import jtk.project4.fleet.field.TableScheduleField;
import jtk.project4.fleet.field.TextSelectedField;
import nl.coderight.jazz.action.Action;
import nl.coderight.jazz.form.FormHeader;
import nl.coderight.jazz.form.FormLayout;
import nl.coderight.jazz.form.FormView;
import nl.coderight.jazz.form.control.GroupControl;
import nl.coderight.jazz.form.field.TableField;
import nl.coderight.jazz.form.field.TableField.AutoResizeMode;
import nl.coderight.jazz.form.field.button.PushButton;
import nl.coderight.jazz.form.validation.ValidationError;



public class pmScheduleSetupView extends FormView{
	private FormHeader formHeader;
	private PushButton helpButton;
	private PushButton closeButton;
	private TableField<String> scheduleTable ;
	private Action cancelAction;
	@Override
	protected void init() {
		createFields();
		createLayout();		
	}	
	
	private void createAction()
	{
		cancelAction = new CancelAction();
		
	}
	
	private void createFields(){
		helpButton = new PushButton("helpAction");
		closeButton = new PushButton(new CancelPMScheduleSetupAction());
		
		scheduleTable = new TableField<String>("schedules","schedule");
		scheduleTable.setTitle("headerscheduleTable");
		scheduleTable.setAutoResizeMode(AutoResizeMode.OFF);
		scheduleTable.getSelectionValues();
		
		//add columns
		scheduleTable.addColumn("label.task","task");
		//scheduleTable.addColumn("label.enable","enable");
		scheduleTable.addColumn("label.type","type");
		scheduleTable.addColumn("label.priority","priority");
		scheduleTable.addColumn("label.dateInterval","dateInterval");
		scheduleTable.addColumn("label.fixedExpireDate","fixedExpireDate");
		scheduleTable.addColumn("label.advancedNotifyDays","advancedNotifyDays");
		scheduleTable.addColumn("label.mileageInterval","mileageInterval");
		scheduleTable.addColumn("label.fixedExpireMileage","fixedExpireMileage");
		scheduleTable.addColumn("label.advancedNotificationMileage","advancedNotificationMileage");
		scheduleTable.addColumn("label.hoursInterval","hoursInterval");
		scheduleTable.addColumn("label.fixedExpireHours","fixedExpireHours");
		scheduleTable.addColumn("label.advancedNotificationHours","advancedNotificationHours");
		scheduleTable.addColumn("label.linkedService","linkedService");
		
		//Sort
		scheduleTable.sort("task", SortOrder.ASCENDING);

	}
	
	private void createLayout() {
		setHeader(createHeader());
		addField(createForm());
	}
	
	private FormHeader createHeader() {
		formHeader = new FormHeader();
		formHeader.setTitle("pmScheduleSetup.header.form");
		return formHeader;
	}
	
	private GroupControl createForm1() {
		GroupControl form = new GroupControl();
		form.setLayout(new FormLayout())
		
		.addField(new ScheduleField("Schedule"))
		.addRow()
		.addField(scheduleTable)
		.addRow()
		.addField(new TextSelectedField("TextSelected"))
		.addRow()
		.addField(new PMServicesField("PMServices"))
		
		
		;
		return form;
	}
	
	private GroupControl createForm() {
		GroupControl form = new GroupControl();
	
		form.addField(createForm1(),NORTH);
		form.addField(createButtons(), SOUTH);		
		return form;
	}
	
	private GroupControl createButtons() {
		GroupControl buttons = new GroupControl();
		buttons.setLayout(new FlowLayout(FlowLayout.RIGHT));
		buttons.addField(helpButton);
		buttons.addField(closeButton);
		return buttons;
	}
	
	public void handleEvent(PMScheduleSetupEvent evt)
	{
		switch (evt.getType())
		{
		case CANCEL:
			close();
			break;
				
			default:
				propagateEvent(evt);
				break;
		}
		
	}
	
	

}
